package com.jihu.design.behavioral.interpreter;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author jihu
 * @date 2021/10/9
 */
public class Area {
    Set<String> citys = new HashSet<>();
    Set<String> types = new HashSet<>();

    IDCardExoression idCardReader;

    public Area(){
        citys.addAll(Arrays.asList("武汉市","上海市"));
        types.addAll(Arrays.asList("医生","老大","儿童"));

        TerminalExpression cityExp = new TerminalExpression(this.citys,":");
        TerminalExpression typeExp = new TerminalExpression(this.types,"-");

        //以上满足一个即可
        idCardReader = new OrExpression(cityExp,typeExp);
    }

    void getTicket(String expression){
        boolean interpret = idCardReader.interpret(expression);

        if(interpret){
            System.out.println("恭喜你,免票通过......");
        }else{
            System.out.println("对不起,请两元购票......");
        }
    }



}
